package vec;
/**
 * Dmitry.Konovalov@jcu.edu.au Dmitry.A.Konovalov@gmail.com 16/10/12, 1:31 PM
 */
public class vec_math {
private static final int DUFF_SIZE = 8;
public static double dot(int minI, int maxI, double[] v, double[] v2) {
  int count = maxI - minI + 1;
  double s = 0;
  int n = (count + DUFF_SIZE - 1) / DUFF_SIZE - 1;
  int i = minI;
  int key = count % DUFF_SIZE;
  switch (key) {
    case 0:        s += v[i] * v2[i];        i++;
    case 7:        s += v[i] * v2[i];        i++;
    case 6:        s += v[i] * v2[i];        i++;
    case 5:        s += v[i] * v2[i];        i++;
    case 4:        s += v[i] * v2[i];        i++;
    case 3:        s += v[i] * v2[i];        i++;
    case 2:        s += v[i] * v2[i];        i++;
    case 1:        s += v[i] * v2[i];        i++;
  }
  for (; n > 0; n--) {
    s += v[i] * v2[i];      i++; //1
    s += v[i] * v2[i];      i++; //2
    s += v[i] * v2[i];      i++; //3
    s += v[i] * v2[i];      i++; //4
    s += v[i] * v2[i];      i++; //5
    s += v[i] * v2[i];      i++; //6
    s += v[i] * v2[i];      i++; //7
    s += v[i] * v2[i];      i++; //8
  }
  return s;
}
}
